package com.liu.thread.ch06;

public class T7  extends Thread{
	
	private static int ticket=20;
	private Object obj=new Object();
	@SuppressWarnings("static-access")
	@Override
	public void run() {
		
		while(true){
			synchronized(obj){
				if(ticket>1){
					try {
						Thread.currentThread().sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println(Thread.currentThread().getName()+"售票，票号为："+ticket);
					ticket=ticket-1;
				}else{
					System.out.println("票买完了");
					break;
				}
			}
		}

	}

}
